<template>
  <div class="email-verification">
    <h2>Email Verification</h2>
    <el-form label-position="left" label-width="200px" :model="emailForm">
      <el-form-item label="Country Code">
        <el-select v-model="emailForm.region" placeholder="Thailand 66">
          <el-option label="区域一" value="shanghai"></el-option>
          <el-option label="区域二" value="beijing"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="Phone Number">
        <el-input v-model="emailForm.email" placeholder="Enter Phone Number"></el-input>
      </el-form-item>
      <el-form-item label="SMS Code">
        <el-input v-model="emailForm.emCode" class="email-code" placeholder="Enter SMS Code"></el-input>
        <el-button
          :type="bottonType"
          plain
          class="get-code"
          :disabled="disabled"
          @click="getEnailCode"
        >{{countTime}}</el-button>
      </el-form-item>
      <el-form-item label="Email Code">
        <el-input v-model="emailForm.smsCode" class="email-code" placeholder="Enter Email Code"></el-input>
        <el-button type="warning" class="get-code" plain>Get Code</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" class="email-confirm">CONFIRM</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { setTime } from "@/filter/index";
export default {
  data() {
    return {
      disabled: false,
      countTime: "Get Code",
      bottonType: "warning",
      emailForm: {
        email: "",
        emCode: "",
        smsCode: ""
      }
    };
  },
  methods: {
    getEnailCode() {
      this.gecountTime();
    },
    /**
     * 按钮倒计时
     * ---------------
     */
    gecountTime() {
      let timer = null;
      let TIME_COUNT = 60;
      if (!timer) {
        this.timer = setInterval(() => {
          if (TIME_COUNT > 0 && TIME_COUNT <= 60) {
            TIME_COUNT--;
            this.disabled = true;
            this.bottonType = "";
            this.countTime = `${TIME_COUNT}s`;
          } else {
            this.disabled = false;
            this.bottonType = "warning";
            this.countTime = "Get Code";
            clearInterval(this.timer);
            this.timer = null;
          }
        }, 1000);
      }
    }
  }
};
</script>
<style lang="less" scoped>
.email-verification {
  height: 100vh;
  h2 {
    font-size: 26px;
    display: inline-block;
    width: 100%;
    padding-bottom: 20px;
    border-bottom: 2px solid #edf0f4;
  }
  .el-form {
    padding: 45px 160px 0 0;
    .email-code {
      width: 450px;
      margin-right: 38px;
      display: inline-block;
    }
    .get-code {
      width: 105px;
    }
    .email-confirm {
      width: 100%;
    }
  }
}
</style>